import { getEnvTitle } from './env'
import { isUndefined } from './typeof'

/**
 * 根据用户参数及 .env .env.production .env.develop 设置app标题
 * @param title 用户要求的标题
 */
export function setAppTitle(title?: string) {
  title = title || getEnvTitle()
  if (!isUndefined(title)) {
    document.title = title
  }
}

const resizeHooks: (() => void)[] = []

window.onresize = () => {
  for (const f of resizeHooks) {
    f()
  }
}

export function registerWindowResize(hook: () => void) {
  resizeHooks.push(hook)
}
